package com.ly.mpayment.persist.service.user;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.ly.mpayment.persist.entity.DownShopInfo;
import com.ly.mpayment.persist.entity.User;
import com.ly.mpayment.persist.hibernate.Page;
import com.ly.mpayment.persist.service.AbstractService;
@Service
public class UserServiceImpl extends AbstractService<User, Serializable> implements IUserService {

	@Override
	public User findOneUser(String phonenum) {
		return this.findUnique("select u from User u where u.userstatus != 0  and u.phonenum = ? ", phonenum);
	}

	@Override
	public boolean updateUser(User user) {
		if(user != null){
			this.saveOrUpdate(user);
			return true;
		}
		return false;
	}

	@Override
	public boolean addUser(User user) {
		if(user != null){
			this.saveOrUpdate(user);
			return true;
		}
		return false;
	}

	@Override
	public Page<User> findPageUser(Map<String, Object> parameters, int start,int pageSize) {
		return this.findPageByNamed("select u from User u where u.userstatus != 0 and u.usertype = 1 #[ and u.username like :shopName]#  #[ and u.phonenum like :phonenum]# " +
				" #[ and u.remark like :remark]# order by u.username", parameters, start, pageSize);
	}

	@Override
	public User findByUserid(String uuid) {
		return this.findUnique("select u from User u where u.userstatus != 0 and u.useruuid = ? ",uuid);
	}

	@Override
	public boolean updateShop(User user) {
		if(user != null){
			this.saveOrUpdate(user);
			return true;
		}
		return false;
	}

	@Override
	public User addUserShop(User user) {
		if(user != null){
			return this.saveOrUpdate(user);
		}
		return null;
	}

	@Override
	public User findUserName(String userName) {
		return this.findUnique("select u from User u where u.username = ? ", userName);
	}


	@Override
	public List<User> findShopBroadbandList(Map<String, Object> parameters) {
		return this.findNameAll(
				"select u from User u where u.usertype = 1 or u.usertype =2 ",
				parameters);
	}

}
